# Copyright 2003 Hirotaka Ogawa. This code cannot be redistibuted without
# permission from h-ogawa@aist.go.jp.
#
# <$MTDynamicEntryPermalink$>
# - a replacement of <$MTEntryPermalink$>, which uses mt-view.cgi.
#
# Version History
#
#	1.0 - Dec 06 2003
#	Initial release
#

use MT::Template::Context;
package MT::plugins::MTDynamicEntryPermalink;

my $VERSION = '1.0';

MT::Template::Context->add_tag(DynamicEntryPermalinkVersion => sub { $VERSION } );
MT::Template::Context->add_tag(DynamicEntryPermalink => \&MTDynamicEntryPermalink );

sub MTDynamicEntryPermalink {
  my $cfg = MT::ConfigMgr->instance;
  my $viewscript_uri = $cfg->CGIPath . $cfg->ViewScript;
  my $ctx = $_[0];
  my $entry = $ctx->stash('entry') or return '';
  my $blog_id = $ctx->stash('blog_id');
  my $entry_id = $entry->id;
  return $viewscript_uri . '/' . $blog_id . '/entry/' . $entry_id;
}

1;
